package com.zdj.email.controller;

import com.zdj.email.common.R;
import com.zdj.email.entity.*;
import com.zdj.email.service.MailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author: wangxl
 * @Date: 2019/3/28 11:54
 */
@Api(tags = "邮件发送接口")
@Controller
@RequestMapping("/email")
public class EmailController {

    @Autowired
    MailService mailService;
    /**
     * 发送简单的文本邮件
     *
     * @return
     */
    @ApiOperation(value = "发送简单的文本邮件", httpMethod = "POST",
            notes = "发送一封简单文本邮件，收件人可以是多人，可指定抄送人，密送人，邮件发送者指定为" +
                    "系统配置账户！",
            response = R.class)
    @PostMapping("/simple")
    public R SimpleMail(@RequestBody SimpleEntity entity) {
        mailService.addSimpleMail(entity);
        mailService.sendSimple();
        return R.ok();
    }

    /**
     * 发送html邮件
     *
     * @return
     */
    @ApiOperation(value = "发送html邮件", httpMethod = "POST",
            notes = "发送一封html邮件，收件人可以是多人，可指定抄送人，密送人，邮件发送者指定为" +
                    "系统配置账户！",
            response = R.class)
    @PostMapping("/html")
    public R HtmlMail(@RequestBody HtmlEntity entity) {
        mailService.addHtmlMail(entity);
        mailService.sendOthers();
        return R.ok();
    }

    /**
     * 发送带附件的邮件
     *
     * @return
     */
    @ApiOperation(value = "发送带附件的邮件", httpMethod = "POST",
            notes = "发送一封带附件的邮件，支持多个附件，收件人可以是多人，可指定抄送人，密送人，邮件发送者指定为" +
                    "系统配置账户！",
            response = R.class)
    @PostMapping("/attach")
    public R Attach(@RequestBody AttachEntity entity) {
        mailService.addAttachemntMail(entity);
        mailService.sendOthers();
        return R.ok();
    }

    /**
     * 嵌入静态资源的邮件
     *
     * @return
     */
    @ApiOperation(value = "嵌入静态资源的邮件", httpMethod = "POST",
            notes = "发送一封嵌入静态资源的邮件，收件人可以是多人，可指定抄送人，密送人，邮件发送者指定为" +
            "系统配置账户！",
            response = R.class)
    @PostMapping("/inlineResource")
    public R InlineResource(@RequestBody InlineResourceEntity entity) {
        mailService.addInlineResourceMail(entity);
        mailService.sendOthers();
        return R.ok();
    }

    /**
     * 发送模板邮件
     *
     * @return
     */
    @ApiOperation(value = "发送模板邮件", httpMethod = "POST",
            notes = "发送一封模板邮件，收件人可以是多人，可指定抄送人，密送人，邮件发送者指定为" +
                    "系统配置账户！",
            response = R.class)
    @PostMapping("/template")
    public R template(@RequestBody TemplateEntity entity) {
        mailService.addTemplateMail(entity);
        mailService.sendOthers();
        return R.ok();
    }
}
